package com.hellojava.assembler;

import com.hellojava.dto.OcrHistoryDto;
import com.hellojava.entity.OcrHistory;
import com.hellojava.util.TimeUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dengjihai
 * @create 2017-12-22
 **/
public class OcrHistoryAssembler {


    /**
     * 批量转换成dto
     * @param ocrHistoryList
     * @return
     */
    public static List<OcrHistoryDto> convertToListDto(List<OcrHistory> ocrHistoryList){
        List<OcrHistoryDto> ocrHistoryDtos = new ArrayList<>();
        ocrHistoryList.forEach( ocrHistory ->  ocrHistoryDtos.add(convertToDto(ocrHistory)));
        return  ocrHistoryDtos;
    }


    public static  OcrHistory convertDtoToEntity(OcrHistoryDto ocrHistoryDto){
        OcrHistory ocrHistory = new OcrHistory();
        ocrHistory.setContent(ocrHistoryDto.getContent());
        ocrHistory.setTitle(ocrHistoryDto.getTitle());
        ocrHistory.setLogId(ocrHistoryDto.getLogId());
        ocrHistory.setOpenId(ocrHistoryDto.getOpenId());
        ocrHistory.setImgUrl(ocrHistoryDto.getImgUrl());
        return  ocrHistory;
    }


    public static  OcrHistoryDto convertToDto(OcrHistory ocrHistory){
        if(ocrHistory==null){
            return null;
        }
        OcrHistoryDto ocrHistoryDto = new OcrHistoryDto();
        ocrHistoryDto.setContent(ocrHistory.getContent());
        ocrHistoryDto.setTitle(ocrHistory.getTitle());
        ocrHistoryDto.setLogId(ocrHistory.getLogId());
        ocrHistoryDto.setImgUrl(ocrHistory.getImgUrl());
        ocrHistoryDto.setCreateTime(TimeUtil.dateToString(ocrHistory.getCreateTime(), TimeUtil.DateStyle.YYYY_MM_DD_HH_MM_SS));
        ocrHistoryDto.setOpenId(ocrHistory.getOpenId());
        return  ocrHistoryDto;
    }
}
